﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Base.Common;
using T.FAS.Runtime.Excel.Entity;

namespace T.FAS.Runtime.Excel.Dao
{
    public class ImportTaskLogic
    {
        readonly ImportTaskDao dao = new ImportTaskDao();
        readonly ImportTaskDetailDao importTaskDetailDao = new ImportTaskDetailDao();
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="ImportTask"></param>
        public void CreateTask(ImportTask importTask)
        {
            dao.Add(new List<object> { importTask });
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="ImportTask"></param>
        public void UpdateTask(ImportTask importTask)
        {
            dao.Update(new List<object> { importTask });
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="ImportTask"></param>
        public void UpdateTaskDetail(ImportTaskDetail importTaskDetail)
        {
            importTaskDetailDao.Update(new List<object> { importTaskDetail });
        }
        /// <summary>
        /// 获取过期任务列表
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public List<ImportTask> GetOutofdateTaskList(DateTime date)
        {
            return dao.GetOutofdateTaskList(date);
        }
        /// <summary>
        /// 获取导入任务列表
        /// </summary>
        /// <param name="cdoID"></param>
        /// <returns></returns>
        public List<ImportTask> GetTaskList(string cdoID)
        {
            return dao.GetTaskList(cdoID);
        }
        /// <summary>
        /// 查询导入任务列表
        /// </summary>
        /// <param name="cdoID"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public Dictionary<string, object> GetTaskList(string cdoID, Dictionary<string, string> filter)
        {
            return dao.GetTaskList(cdoID, filter);
        }
        /// <summary>
        /// 获取导入任务
        /// </summary>
        /// <param name="taskID"></param>
        public ImportTask GetTask(string taskID)
        {
            return dao.GetObject(taskID);
        }
        /// <summary>
        /// 查询导入任务明细
        /// </summary>
        /// <param name="taskID"></param>
        public List<ImportTaskDetail> GetTaskDetailList(string taskID)
        {
            return importTaskDetailDao.GetTaskDetailList(taskID);
        }
        /// <summary>
        /// 查询导入任务明细
        /// </summary>
        /// <param name="taskID"></param>
        public Dictionary<string, object> GetTaskDetailList(string taskID, Dictionary<string, string> filter)
        {
            return importTaskDetailDao.GetTaskDetailList(taskID, filter);
        }
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="taskID"></param>
        public void DeleteTask(string taskID)
        {
            importTaskDetailDao.DeleteByTask(taskID);
            dao.Delete(new List<string> { taskID });
        }
        /// <summary>
        /// 删除任务明细
        /// </summary>
        /// <param name="taskID"></param>
        public void DeleteTaskDetail(string detailID)
        {
            importTaskDetailDao.Delete(new List<string> { detailID });
        }
        /// <summary>
        /// 清空任务
        /// </summary>
        public void ClearTask(string cdoID)
        {
            string userID = UserUtil.GetCurrentUserID();
            dao.ClearTask(userID, cdoID);
        }
        /// <summary>
        /// 插入任务明细
        /// </summary>
        /// <param name="importTaskDetails"></param>
        public void CreateTaskDetail(List<ImportTaskDetail> importTaskDetails)
        {
            importTaskDetailDao.Add(importTaskDetails);
        }
        /// <summary>
        /// 根据MD5码查是否存在重复导入
        /// </summary>
        /// <param name="md5"></param>
        /// <returns></returns>
        public bool CheckIsImportByMD5(string md5)
        {
            return dao.CheckIsImportByMD5(md5) > 0;
        }
        /// <summary>
        /// 根据MD5码查是否存在重复导入
        /// </summary>
        /// <returns></returns>
        public bool CheckIsImportByFileName(string cdoID, string userID, string fileName)
        {
            return dao.CheckIsImportByFileName(cdoID, userID, fileName) > 0;
        }
        /// <summary>
        /// 根据文件名称删除 单元测试用
        /// </summary>
        /// <returns></returns>
        public void DeleteByFileName(string fileName)
        {
            dao.DeleteByFileName(fileName);
        }
        /// <summary>
        /// 根据MD5码查行是否存在重复导入
        /// </summary>
        /// <returns></returns>
        public bool CheckIsImport(string cdoID, string uniqueID)
        {
            return importTaskDetailDao.CheckIsImport(cdoID, uniqueID) > 0;
        }
    }
}
